package com.example.smartmedicalsystem.repository;

import com.example.smartmedicalsystem.entity.Comment;
import com.example.smartmedicalsystem.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {
    List<Comment> findAllByOrderByCreatedAtDesc();
    List<Comment> findByReplyIsNull();

    @Query("SELECT c FROM Comment c LEFT JOIN FETCH c.replies WHERE c.parentComment IS NULL")
    List<Comment> findAllRootComments();
}